<template>
    <div class="viewDetails3">
        <!-- 头部 -->
        <!-- <div class="header">
            <x-icon type="ios-arrow-left" size="" class="icon-white" @click="$router.go(-1)"></x-icon>安全检查
        </div> -->
        <!-- 内容部分 -->
        <div class="safeDetails3">
            <ul class="ul1">
                <li class="clearfix">
                    <span class="spa">检查编号</span>
                    <em>{{listArr.No}} </em>
                </li>
                <li class="clearfix">
                    <span class="spa">被检查单位</span>
                    <em>{{listArr.projectName}}</em>
                </li>
                <li class="clearfix">
                    <span class="spa">检查名称</span>
                    <em>{{listArr.CheckName}}</em>
                </li>
                <li class="clearfix">
                    <span class="spa">检查类型</span>
                    <em>{{listArr.checkType}}</em>
                </li>
                <li class="clearfix">
                    <span class="spa">检查时间</span>
                    <em>{{listArr.checkTime}}</em>
                </li>
                <li class="clearfix">
                    <span class="spa">检查区域</span>
                    <em>{{listArr.checkArea}}</em>
                </li>
                <li class="clearfix">
                    <span class="spa">检查内容</span>
                    <em>{{listArr.checkContent}}</em>
                </li>
                <li class="clearfix">
                    <span class="spa">检查重点</span>
                    <em>{{listArr.checkImportant}}</em>
                </li>
            </ul>
            <ul class="ul1"
                style="margin-top:10px;">
                <li class="clearfix">
                    <span class="spaTitle">检查组成员及分工</span>
                </li>
                <li class="clearfix">
                    <span class="spa">检查组长</span>
                    <em>{{listArr.checkGroupLeaderName}} </em>
                </li>
                <ul class="ul_in"
                    v-for="(item,index) in listArr.checkMemberList"
                    :key="index">
                    <li class="clearfix">
                        <span class="spa">成员</span>
                        <em>{{item.memberName}}
                            <span class="sp"
                                  v-if="!item.IsSubmitted">(未提交)</span>
                        </em>
                    </li>
                    <li class="clearfix">
                        <span class="spa">分工</span>
                        <em>{{item.memberWork}} </em>
                    </li>
                </ul>
            </ul>
            <div class="line"></div>
            <!-- 组长 -->
            <div class="ul3"
                 v-if="type==1&&!btn3">
                <h3>检查记录
                    <span v-if="listArr.checkType!='日常检查'">({{listArr.TotalScore}} 分)</span>
                </h3>
                <div class="standard-wrap">
                    <div v-for="(item,index) in  listArr1"
                         v-bind:key="index"
                         class="item-wrap">
                        <standardItem :item="item"
                                      :showChild="showChild"
                                      :selectStandard="selectStandard"></standardItem>
                    </div>
                </div>
            </div>
            <div class="ul3"
                 v-if="type==2 || btn3">
                <h3>检查记录
                    <span>({{listArr.TotalScore}} 分)</span>
                    <em>
                        <x-icon type="ios-plus"
                                size="24"
                                @click="roterAdd"></x-icon>
                    </em>
                </h3>
                <div class="form-section">
                    <div v-for="(item,index) in menulist"
                         :key="index">
                        <template>
                            <div class="form-item form-item-style1 looktest">
                                <div class="label-title">
                                    <label class="lookmsgTwo">{{item.key?item.key:"其他"}}
                                        <!--<span>（90分）</span>-->
                                    </label>
                                </div>
                                <group>
                                    <cell is-link
                                          :border-intent="false"
                                          :arrow-direction="showarr[index]? 'up' : 'down'"
                                          @click.native="showmsg(index)">
                                        <span class="selectspan">共计{{item.value.length}}条隐患</span>
                                    </cell>
                                </group>
                            </div>
                            <template v-if="showarr[index]">
                                <leftmove v-for="(itemlist,indexlist) in item.value"
                                          :key="indexlist"
                                          @removemsg="removemsg(item,index,indexlist)">
                                    <div class="contentlist"
                                         @click="showlistitem(index,indexlist,itemlist)">
                                        <div class="card-padding">
                                            <div class="card-title1">{{itemlist.checkDeptName}}</div>
                                            <div class="card-show">{{itemlist.description}}</div>
                                            <div class="danger-nomal">【{{itemlist.hdLevel[0]}}】
                                                <span>{{itemlist.state?itemlist.state:""}}</span>
                                            </div>
                                        </div>
                                        <img :src="itemlist.uploadImgs[0]?itemlist.uploadImgs[0].url:''"
                                             class="newImage">
                                        <!-- <div class="newImage">
                                            <img :src="itemlist.localIds[0]?itemlist.localIds[0]:''">
                                        </div> -->
                                    </div>
                                </leftmove>
                            </template>
                        </template>
                    </div>
                </div>
            </div>
            <div class="line"></div>
            <!-- 组员不显示-->
            <ul class="ul1"
                style="margin-top:10px;"
                v-if="type==1|| btn3">
                <li class="clearfix">
                    <span class="spaTitle"
                          style="width:200px">生成通知单</span>
                </li>
                <li class="clearfix"
                    v-for="(item,index) in warn"
                    :key="index">
                    <span class="spa"
                          style="width:200px">{{item.name}} </span>
                    <em style="width:100px;"
                        @click="routerGo2(index)">
                        <x-icon type="ios-arrow-right"
                                size="20"
                                style="margin-top:4px;margin-right:10px"></x-icon>
                    </em>
                </li>
            </ul>
            <div class="btn"
                 @click="btn"
                 v-if="subMit">
                提交
            </div>
            <div class="btn2"
                 v-if="!subMit">
                提交
            </div>
        </div>
        <myMenu @clickBack="back"
                backPath='/safeView3'></myMenu>
    </div>
</template>
<script>
import { Actionsheet, Cell, Group, CellBox } from 'vux'
import standardItem from './select2'
import leftmove from './left'
import myMenu from '@/commonComponents/menu'
export default {
    components: {
        Actionsheet,
        Group,
        Cell,
        CellBox,
        standardItem,
        leftmove,
        myMenu
    },
    data () {
        return {
            idd: '',
            subMit: true,
            btn2: true,
            btn3: false,
            btn4: false,
            type: 0, // 1 组长 ,2 组员
            ind: 9999,
            showContent001: false,
            param: {
                allowPaging: true,
                business: 'getSafeCheckDetail',
                data: {
                    safeCheckIdItem: ''
                },
                pageIndex: 0,
                pageSize: 20,
                tokenId: 'D0853C0CE5A6A478F5C613B840394FC3',
                userId: ''
            },
            warn: [{ name: '生成隐患整改通知单' }, { name: '生成设备停用通知单' }, { name: '生成停工通知单' }],
            listArr: [],
            listArr1: [],
            listArr2: [],
            param2: {
                allowPaging: true,
                business: 'GetCheckWorkHiddenDangers',
                data: {
                    CategoryId: '',
                    id: ''
                },
                pageIndex: 0,
                pageSize: 1000,
                tokenId: 'D0853C0CE5A6A478F5C613B840394FC3',
                userId: ''
            },
            subParam: {
                allowPaging: true,
                business: 'SubmitCheckWork',
                data: {
                    HiddenDangerId1: '',
                    HiddenDangerId2: '',
                    HiddenDangerId3: '',
                    addProblemType: 0,
                    id: '',
                    HiddenDangers: []
                },
                pageIndex: 0,
                pageSize: 20,
                tokenId: 'D0853C0CE5A6A478F5C613B840394FC3',
                userId: ''
            },
            uid: '',
            menulist: [],
            showarr: []
        }
    },
    created () {
        var token = JSON.parse(window.localStorage.getItem('userInfo'))
        this.uid = token.userid
        this.param.userId = token.userid
        this.param2.userId = token.userid
        this.subParam.userId = token.userid
        // this.$store.state.hiddenlist1 = ''
        this.$store.state.localId = ''
        this.listArr2 = this.$store.state.HiddenDangers
        this.param.data.safeCheckIdItem = window.sessionStorage.getItem('passId')
        this.param2.data.id = window.sessionStorage.getItem('passId')
        let listget = []
        listget = [...this.$store.state.HiddenDangers]
        this.menulist = [] // 数据过滤
        listget.forEach(
            (item, index) => {
                let flag = true
                for (var indexs = 0; indexs < this.menulist.length; indexs++) {
                    if (item.category == this.menulist[indexs].key) {
                        this.menulist[indexs]['value'].push(item)
                        flag = false
                    }
                }
                if (flag) {
                    this.menulist = [...this.menulist, {
                        key: item.category,
                        value: [item]
                    }]
                }
            }
        )
    },
    mounted () {
        this.dataArr()
    },
    methods: {
        roterAdd () {
            this.$router.push({
                path: 'HideRegister2',
                query: {
                    id: this.$route.query.id
                }
            })
        },
        routerGo2 (index) {
            if (this.btn2) {
                if (index == 0) {
                    this.$router.push({ path: './view3Receipt', query: { type: 'HiddenDangerId1', name: '生成隐患整改通知单', id: this.idd } })
                }
                if (index == 1) {
                    this.$router.push({ path: './view3Receipt', query: { type: 'HiddenDangerId2', name: '生成设备停用通知单', id: this.idd } })
                }
                if (index == 2) {
                    this.$router.push({ path: './view3Receipt', query: { type: 'HiddenDangerId3', name: '生成停工通知单', id: this.idd } })
                }
            } else {
                this.$vux.toast.text('请等待检查组成员检查完成')
            }
        },
        showChild (deptId, item) {
            item.open = !item.open
        },
        selectStandard (item) {
            item.checked = !item.checked
        },
        click (key, item) {
        },
        show (i) {
            this.ind = i
        },
        // 主要数据
        dataArr () {
            this.$axiosAjax.getConfigJson(this.param).then((res) => {
                if (res.status == 200) {
                    this.idd = res.data.data.checkId
                    this.listArr = res.data.data
                    this.subParam.data.id = res.data.data.checkId
                    if (res.data.data.checkGroupLeaderId == this.uid) { // 组长
                        this.type = 1
                        this.dataArr2()
                    } else { //  成员才调取借口
                        this.type = 2
                    }
                    this.$store.state.hiddenlist1[this.$route.query.id] = Object.assign({}, this.$store.state.hiddenlist1[this.$route.query.id], {
                        'deptName': res.data.data.projectName,
                        'deptId': res.data.data.ProjectId,
                        'projectDutyPerson': res.data.data.ProjectDutyPerson
                    })
                    window.sessionStorage.setItem('pid', res.data.data.ProjectId)
                    this.$store.state.checkcompany.Category = res.data.data.checkedDepartSir
                    var list = res.data.data.checkMemberList
                    for (var k of list) {
                        if (!k.IsSubmitted && k.memberId != res.data.data.checkGroupLeaderId) {
                            this.btn2 = false // 未提交 && 不是组长
                        }
                        if (this.uid == res.data.data.checkGroupLeaderId && k.memberId == this.uid) { // 又是成员,也是组长
                            this.btn3 = true
                        }
                    }
                }
            }
            )
        },
        // 检查记录下的数据
        dataArr2 () {
            this.$axiosAjax.getConfigJson(this.param2).then((res) => {
                if (res.status == 200) {
                    var arr = res.data.data
                    var a = []
                    for (var k of arr) {
                        for (var j of k.problemSummaries) {
                            a.push(j.No)
                            j.checked = false
                        }
                        k.open = false
                    }
                    this.total = a.length
                    this.listArr1 = arr
                }
            })
        },
        back () {
            window.sessionStorage.removeItem('pid')
            this.subParam.data.HiddenDangerId1 = []
            this.subParam.data.HiddenDangerId2 = []
            this.subParam.data.HiddenDangerId3 = []
            this.subParam.data.HiddenDangers = []
            this.subParam.data.id = ''
            this.$router.push('./safeView3')
            this.$store.state.HiddenDangers = []
        },
        // 提交
        btn () {
            if (this.btn2 || this.type == 2) {
                let arr = []
                let formData = new FormData()
                this.$store.state.HiddenDangers.forEach(
                    (item, index) => {
                        item.uploadImgs.forEach(
                            (itemlist, indexlist) => {
                                formData.append(itemlist.name, item['images'][indexlist])
                            }
                        )
                        arr = [...arr, {
                            'category': item.category, // 1
                            'categoryId': item.categoryId, // 1
                            'categoryIds': item.categoryId,
                            'checkDeptCode': item.checkDeptCode, // d
                            'checkDeptId': item.checkDeptId, // d
                            'checkDeptName': item.checkDeptName, // d
                            'checkPerson': item.checkPerson, // d
                            'checkPersonId': item.checkPersonId, // d
                            'checkTime': item.checkTime, // 1
                            'checkWorkId': this.subParam.data.id, // 检测信息
                            'deptId': item.deptId, // 所属项目ID
                            'deptName': item.deptName, // 所属项目名称
                            'description': item.description, // 隐患描述
                            'hdLevel': item.hdLevel[0],
                            'isApproved': item.isApproved,
                            'isBig': item.hdLevel[0] == '一般隐患' ? 0 : 1,
                            'isChecked': item.isChecked,
                            'isResolved': item.isResolved,
                            'isSubmited': item.isSubmited,
                            'localId': item.localId,
                            'measure': item.measure,
                            'measureEdit': item.isChecked,
                            'no': item.no,
                            'problemImgs': item.problemImgs,
                            'projectDutyPerson': item.projectDutyPerson, // 项目负责人姓名||
                            'registerUserId': item.registerUserId, // 登陆拿
                            'resolveArea': item.resolveArea,
                            'resolveAreaDutyPerson': item.resolveAreaDutyPerson,
                            'resolveAreaDutyPersonId': item.resolveAreaDutyPersonId,
                            'resolveEndTime': item.resolveEndTime,
                            'resolveStartTime': item.resolveStartTime,
                            'tel': item.tel,
                            'userId': item.userId,
                            'ResolveDeptName': item.ResolveDeptName, // 整改单位
                            'ResolveDeptCode': item.ResolveDeptCode,
                            'ResolveDeptId': item.ResolveDeptId,
                            'ResolveDutyPersonName': item.ResolveDutyPersonName,
                            'ResolveGroupId': item.ResolveGroupId,
                            'ResolveGroup': item.ResolveGroup,
                            'ResolveGroupDutyPerson': item.ResolveGroupDutyPerson
                        }]
                    }
                )
                this.subParam.data.HiddenDangerId1 = window.sessionStorage.getItem('HiddenDangerId1')
                this.subParam.data.HiddenDangerId2 = window.sessionStorage.getItem('HiddenDangerId2')
                this.subParam.data.HiddenDangerId3 = window.sessionStorage.getItem('HiddenDangerId3')
                for (var k in this.$store.state.HiddenDangers) {
                    if (this.$store.state.HiddenDangers[k].state == '未填写') {
                        this.$vux.toast.text('有未填写选项,请先完善再提交')
                        return false
                    }
                }
                this.$vux.loading.show()
                this.subMit = false
                this.subParam.data.HiddenDangers = arr
                this.$axiosAjax.getConfigJson(this.subParam, formData).then((res) => {
                    this.subMit = true
                    if (res.data.code == 0) {
                        this.$vux.loading.hide()
                        this.subParam.data.HiddenDangerId1 = []
                        this.subParam.data.HiddenDangerId2 = []
                        this.subParam.data.HiddenDangerId3 = []
                        this.subParam.data.HiddenDangers = []
                        window.sessionStorage.removeItem('pid')
                        this.$store.state.HiddenDangers = []
                        this.$router.push('./safeView3')
                    }
                })
            } else {
                this.$vux.toast.text('请等待检查组成员检查完成')
            }
        },
        showmsg (index) {
            this.showarr[index] = !this.showarr[index]
            this.$forceUpdate()
        },
        removemsg (item, index, indexlist) {
            let arr = this.menulist[index]['value']
            arr.splice(indexlist, 1)
            this.$store.state.HiddenDangers.splice(indexlist, 1)
            this.menulist[index]['value'] = arr
            this.$store.state.selectidlist1.forEach(
                (newitem, newindex) => {
                    if (item.localId = newitem) {
                        this.$store.state.selectidlist1.splice(newindex, 1)
                    }
                }
            )
            this.$store.state.selectidlist2.forEach(
                (newitem, newindex) => {
                    if (item.localId = newitem) {
                        this.$store.state.selectidlist2.splice(newindex, 1)
                    }
                }
            )
            this.$store.state.selectidlist3.forEach(
                (newitem, newindex) => {
                    if (item.localId = newitem) {
                        this.$store.state.selectidlist3.splice(newindex, 1)
                    }
                }
            )
            this.$forceUpdate()
        },
        showlistitem (index, indexlist, item) {
            this.$store.state.hiddenlist1[item.localId] = item
            this.$store.state.localId = item.localId
            this.$router.push({ path: '/hideRegister2', query: { 'localId': item.localId, id: this.$route.query.id } })
        }
    }
}
</script>
<style lang="less" scoped>
.viewDetails3 {
    width: 100%;
    height: 100%;
    .header {
        width: 100%;
        height: 40px;
        line-height: 40px;
        text-align: center;
        position: relative;
        font-size: 18px;
        background: #2269ff;
        color: #fff;
        .vux-x-icon {
            fill: cornsilk;
            position: absolute;
            left: 0;
            top: 5px;
            width: 30px;
            height: 30px;
        }
    }
    .safeDetails3 {
        height: 603px;
        width: 100%;
        background-color: #ebeef2;
        padding-top: 10px;
        .ul1 {
            width: 100%;
            padding: 0 10px;
            background-color: #fff;
            margin-bottom: 10px;
            li,
            li .ul_in {
                padding: 10px 0;
                border-bottom: 1px solid #eee;
                width: 100%;
                height: 50px;
                line-height: 30px;
                position: relative;
                .vux-x-icon {
                    fill: #999;
                    float: right;
                    position: absolute;
                    top: 12px;
                    right: -10px;
                }
                .spa {
                    // float: left;
                    width: 96px;
                    font-size: 14px;
                    color: #333;
                }
                .spaTitle {
                    height: 30px;
                    line-height: 30px;
                    float: left;
                    font-size: 16px;
                    width: 196px;
                    color: #2269ff;
                }
                em {
                    float: right;
                    font-size: 14px;
                    width: 240px;
                    height: 30px;
                    line-height: 30px;
                    text-align: right;
                    margin-right: 10px;
                    overflow: hidden;
                    text-overflow: ellipsis;
                    white-space: nowrap;
                    color: #999;
                    .sp {
                        color: red !important;
                    }
                }
                .vux-cell-value {
                    float: right;
                    margin-right: 20px;
                }
            }
        }
        .ul3 {
            background-color: #fff;
            padding: 0 0 0 10px;
            h3,
            h4 {
                margin-top: 10px;
                height: 40px;
                line-height: 40px;
                font-size: 16px;
                color: #2269ff;
                padding: 0 10px;
                padding-left: 0 !important;
                border-bottom: 1px solid #eee;
                background-color: #fff;
                span {
                    font-size: 16px;
                    height: 40px;
                    line-height: 40px;
                    color: #999;
                }
                em {
                    font-size: 14px;
                    float: right;
                    height: 20px;
                    .vux-x-icon {
                        fill: #09c13b;
                        margin-top: 8px;
                    }
                }
            }
            h4 {
                font-size: 16px;
                color: #333;
                em {
                    position: relative;
                    .vux-x-icon {
                        fill: #999;
                        float: right;
                        width: 30px;
                        height: 30px;
                        margin-top: 6px;
                    }
                }
            }
        }
        .btn {
            width: 200px;
            height: 40px;
            line-height: 40px;
            text-align: center;
            border-radius: 25px;
            background-color: #2269ff;
            margin: 40px auto;
            color: #fff;
        }
        .btn2 {
            width: 200px;
            height: 40px;
            line-height: 40px;
            text-align: center;
            border-radius: 25px;
            background-color: #999;
            margin: 40px auto;
            color: #fff;
        }
    }
    .weui-cell {
        padding: 10px;
        // border-bottom:1px solid #eee;
    }
    .vux-label {
        font-size: 16px;
    }
    .weui-cells {
        margin-top: 0;
    }
    .weui-cell__ft {
        em {
            font-size: 14px;
        }
    }
    .dele {
        overflow: hidden;
        background-color: #fff;
        .list-item {
            position: relative;
            height: 120px;
            -webkit-transition: all 0.2s;
            transition: all 0.2s;
            border-bottom: 1px solid #eee;
            .list-box {
                padding: 0 10px;
                display: flex;
                align-items: center;
                -webkit-box-sizing: border-box;
                box-sizing: border-box;
                justify-content: flex-end;
                position: absolute;
                top: 0;
                right: 0;
                bottom: 0;
                left: 0;
                font-size: 0;
                .list_Left {
                    float: left;
                    width: 220px;
                    height: 120px;
                    h2 {
                        width: 100%;
                        font-size: 18px;
                        margin-top: 14px;
                    }
                    p {
                        font-size: 16px;
                        width: 100%;
                        overflow: hidden;
                        text-overflow: ellipsis;
                        white-space: nowrap;
                        margin-top: 14px;
                    }
                    h5 {
                        margin-top: 14px;
                        font-size: 16px;
                        width: 100%;
                        em {
                            color: #ffb400;
                        }
                    }
                }
                .list_Right {
                    width: 150px;
                    height: 126px;
                    float: right;
                    padding: 14px 0;
                    img {
                        width: 100%;
                        height: 100%;
                        // border: 1px solid #fff;
                        border-radius: 5px;
                    }
                }
            }
        }
        .n1 {
            color: #fe0100;
        }
        .n2 {
            color: #ff7034;
        }
    }
    .affirm-wrap {
        position: fixed;
        z-index: 5;
        bottom: 0;
        left: 0;
        right: 0;
        background: #ebeef2;
    }
    .standard-name span {
        margin-left: 20px;
        font-size: 16px;
    }
    .iconfont {
        margin-left: 20px;
    }
    .item-wrap {
        // padding-left: 20px;
        background: #fff;
        position: relative;
        z-index: 2;
        // margin-top: 5px;
    }
    .selectspan {
        margin-right: 8px;
        color: #b0b0b0;
        font-size: 14px;
    }
    .card-padding {
        height: 100px;
        width: 230px;
        padding-right: 30px;
    }
    .newImage {
        width: 100px;
        height: 74px;
        border-radius: 7px;
    }
    .newImage img {
        width: 100%;
        height: 100%;
    }
    .contentlist {
        width: 100%;
        height: 106px;
        display: flex;
        justify-content: space-between;
        padding: 16px 20px 16px 0;
        border-bottom: 1px solid #efeff4;
    }
    .card-title1 {
        width: 100%;
        //   height:15px;
        line-height: 15px;
        font-size: 15px;
        font-weight: bold;
        color: #333333;
        margin-top: 0;
        padding-top: 4px;
        overflow: hidden;
        text-overflow: ellipsis; /* 当对象内文本溢出时显示省略标记(...) ；需与overflow:hidden;一起使用。*/
        white-space: nowrap; /*不换行 */
    }
    .card-show {
        padding-top: 12px;
        width: 100%;
        height: 26px;
        line-height: 14px;
        font-size: 14px;
        color: #666666;
        overflow: hidden;
        text-overflow: ellipsis; /* 当对象内文本溢出时显示省略标记(...) ；需与overflow:hidden;一起使用。*/
        white-space: nowrap; /*不换行 */
    }
    .danger-nomal {
        margin-top: 20px;
        color: #ff7333;
        font-size: 14px;
    }
}
.line {
    border-bottom: 10px solid #ebeef2;
}
</style>
<style>
.viewDetails3 .form-item {
    margin-left: 0;
    padding-left: 0;
}
.viewDetails3 .delete {
    padding-left: 0 !important;
}
</style>
